package javbot.keydata;
import java.awt.event.KeyEvent;

public class KeyData {

	private static final String OUT_OF_RANGE_ASCII = "Ascii should be between 33 & 126";
	// maps ascii to KeyPress (for ascii 0 to 255)
	KeyComb[] vkCodes = new KeyComb[256];
	public KeyDataProps keyDataProps;	
	
	public KeyData() {
		
		keyDataProps = new KeyDataProps(this);
		
		for (int i=0; i< vkCodes.length;i++) {
			vkCodes[i] = new KeyComb();
		}
	}

	public KeyComb getVkCodeForChar(int ascii) throws Exception {
		if (0 <= ascii || ascii <= 255)
			return vkCodes[ascii];
		else
			throw new Exception(OUT_OF_RANGE_ASCII);
	}
		
	public void setVkCodeOfAscii(int ascii, int vkCode, boolean shift) throws Exception {
		if (0 <= ascii || ascii <= 255) {
			vkCodes[ascii].vkCode = vkCode;
			vkCodes[ascii].shift = shift;
		}
		else
			throw new Exception(OUT_OF_RANGE_ASCII);
	}
	
	public void printKeyData(){
		for (int i=0; i< vkCodes.length;i++) {
			int asciiCode =  i;
			int vkCode = vkCodes[asciiCode].vkCode;
			if (vkCodes[i].vkCode != 0) {
				System.out.print("ASC " +  asciiCode + "\t");
				System.out.print((char) asciiCode + "\t");
				System.out.print(KeyEvent.getKeyText(vkCode) + " (");
				System.out.print(vkCodes[asciiCode].shift + ")");
				System.out.print("\n");
			}
		}
	}
	
	public class KeyComb {
		public int vkCode;
		public boolean shift;
		
		public String toString() {
			
			return vkCode + "|" + shift;
		}
	}
	
	
}
